home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Libris Britannia 4
/
science library(b).zip
/
science library(b)
/
PROGRAMM
/
PASCAL
/
0407.ZIP
/
RPN.DOC
< prev
next >
Wrap
Text File
|
1986-05-05
|
11KB
|
280 lines
RPN: Programmable RPN calculator by Frank LaRosa, 1985
-------------------------------------------------------------------
This is a public domain, user supported program. If you use this
program, please send a contribution of $10 to the programmer:
Frank LaRosa
46 Twixt Hills Rd.
St. James, NY 11780
SYSOP, Searchlight bbs (516) 724-0971
Please feel free to distribute this program. You may modify the
program and documentation so long as you do not remove my name from
the program or remove this message from the documentation.
-------------------------------------------------------------------
RPN simulates a multifunction, programmable Reverse Polish Notation
calculator. The command set is loosely based on the HP-11C
scientific calculator, although I have added and deleted many
commands. There are two types of input:
COMMANDS: One-letter commands to direct the operation of the
program. Used to create, save and load programs, etc.
STATEMENTS: Three-letter commands to perform calculator operations.
Statements can be executed directly or made into a
program.
GETTING STARTED
The RPN archive contains the following files:
RPN.EXE The RPN program
RPN.BAS BASIC source code to RPN.EXE (Ascii format)
RPN.DOC This documentation
???.RPN Various RPN sample files
To run the program, type RPN. The command prompt, RPN>, will appear.
The BASIC source code is included; you may load RPN.BAS under BASIC
and type RUN, but the .EXE version executes much faster. The BASIC
source code is included for those who wish to modify the program.
At the RPN> prompt, enter "?" for a list of statements and commands.
RPN COMMANDS
The RPN commands are:
Insert, List, Go, Delete, Save, Recall, Files, Xamine, ?, Quit
Commands are entered by typing the FIRST LETTER of the command,
optionally followed by parameters. You must use capital letters.
Command: Insert Syntax: I<n>
The Insert command builds a program of RPN statements. Type I by
itself to enter lines at the end of the current program; or use I
followed by a number to insert in the middle of the file. Program
statements are three letters, optionally followed by a number. The
Insert command converts each statement to an integer code and will
only take valid statements, generating an error message if an
invalid command or parameter is entered. To exit from Insert mode,
just press return on a blank line.
Command: List Syntax: L<n> <filename>
List the program in memory. If parameter n is given, list from line
n on. Lines in the program are NOT numbered sequentially, they are
numbered according to their position in memory. Simple statements
take up one memory location, while statements with parameters take
two or more. When listing you must give a line number that actually
corresponds to the first location of a command. If this is not done,
the listing will start at the next valid line or an error may occur.
To pause the listing, press any key; press any key again to
continue. To abort the listing, press ESC.
If a filename is given, the list is output to the file instead of to
the console screen.
Command: Go Syntax: G<n> <filename>
The Go command executes the program in memory. If n is given,
execution begins at line n; else execution begins at line 1. You can
press the ESC key to break the program.
If a filename is given, program output (PRX and PRS statements) is
redirected to the file instead of the screen.
Command: Delete Syntax: Dn<,m>
If n only is given, deletes line n. If n and m given, deletes lines
n thru m. Both n and m must be legal line numbers, or the command
will abort.
Command: Save Syntax: S <filename>
Save the program to a file. If filename is left out, you are
prompted for it. You may include a drive letter and pathname in the
filename, however you may not include an extension; the default
extension .RPN will be used automatically. The file is saved as a
series of binary numbers and is only readable by the RPN program.
Command: Recall Syntax: R <filename>
Recall file saved by Save command. Default extension of .RPN is
used. Any program in memory is overwritten.
Command: Files Syntax: F <filename>
Shows the disk directory. A filename or wildcard mask may be given.
Command: Xamine Syntax: X<n>
Examines registers. If X is entered alone, the contents of the stack
(registers X, Y, Z and T) are shown. If n is included, the contents
of external register n are displayed.
Command: ? Syntax: ?
Displays a list of valid statements and commands on the screen.
Command: Quit Syntax: Q
Quits the program and returns to DOS.
RPN STATEMENTS
The heart of the RPN program are the statements that perform
calculations. The calculator is structured as follows:
1. A four element stack. The stack registers are labeled X, Y, Z and
T, with X being the bottom element of the stack. Most
computations are done on these registers.
2. External registers. Up to 1000 external registers are available
to store numbers. The registers can be addressed directly or
indirectly by the program statements.
3. Program memory. Memory that holds program instructions.
All statements are 2 or 3 letters long; some have parameters.
Statements may be incorporated into programs or they may be executed
directly at the RPN> prompt. All calculations are done using real
numbers to a precision of 6 decimal places.
I. STACK CONTROL STATEMENTS
CON n - Enter constant n into the X regiser, and shift the stack
upwards by 1 element.
ENT - Shift stack upwards. X register copied to Y register.
RLU - Shift stack up. T register wraps to X register.
RLD - Shift stack down. X register wraps to T register.
EXC - Exchange X register with Y register.
CLX - Clear X regiser (set to 0).
CLS - Clear stack (all registers to 0).
II. REGISTER CONTROL STATEMENTS
STO n - Store X register in register n.
RCL n - Recall register n into stack. Stack shifts up.
SUM n - Add contents of X register to register n.
PRD n - Register n is multiplied by X register.
STI n - Store indirect. The contents of register n points to the
register where X is saved. Register n must contain a number
from 1 to 1000.
RCI n - Recall indirect. Register n points to register to recall.
CLR - Clear all registers to 0.
III. MATHEMATICAL FUNCTIONS
ADD - Add X and Y registers. Result goes to X register, and stack
is shifted downwards.
SUB - Subtract X from Y. Stack shifted down.
MPY - Multiply X and Y, move stack down.
DIV - Divide Y by X, move stack down.
EXP - Exponentiation; raise Y to X power. Shift stack down.
CHS - Multiply X register by -1.
ABS - Absolute value of X.
1/X - Divide 1 by contents of X register.
LNX - Take natural log (base e) of X.
LOG - Take common log (base 10) of X.
ALN - Raise e to power of X.
ALG - Raise 10 to power of X.
SIN - Sine of X in Radians.
COS - Cosine of X.
TAN - Tangent of X.
ASN - Arcsine of X (inverse of SIN).
ACS - Arc cosine (inverse COS).
ATN - Arc tangent (inverse TAN).
SQR - Square root of X.
SQU - Square of X (X^2).
INT - Take integer value of X.
FRC - Take fractional value of X.
ROU n - Round X off to n decimal places.
PI - Enter value of Pi into X register. Stack is shifted up.
RND - Enter random number between 0 and 1. Shift stack up.
IV. FLOW CONTROL STATEMENTS
LBL n - Sets a label in the program. n is a number from 1 to 50.
GTO n - Goto statement. Processing jumps to LBL n statement.
GSB n - Gosub to label n. Gosubs may be nested 10 deep.
RTN - Return from subroutine to statement following GSB.
GTI n - Goto indirect. The contents of register n contains the label
where processing is to jump. Register n must contain a valid
label number (1 thru 50).
GSI n - Gosub indirect. Register n points to label to gosub to.
X=Y - Conditional branching instruction. If condition is true
(contents of X equals contents of Y), processing continues
at the next instruction. If false, the next instruction is
skipped. Usually, a GTO or GSB instruction follows X=Y.
X#Y - Conditional, X unequal to Y.
X<Y - Conditional, X less than Y.
X=0 - Conditional, X equal to 0.
X#0 - Conditional, X unequal to 0.
X<0 - Conditional, X less than 0.
DSZ n - Decrement and Skip on Zero. Contents of register n is
decremented by 1. If result is zero, the next instruction is
skipped; if not, processing continues at next instruction.
END - End program and return to control mode.
V. INPUT AND OUTPUT
PRX - Print value of X register on screen.
PRS - Print X, Y, Z and T registers in 4-across format.
FIX n - Set number of decimal places to use with PRX and PRS.
INP - Input value from keyboard to X register. Stack moves up.
NOP - No operation. Do nothing.
PROGRAMMING NOTES:
Values used in indirect expressions (STI, GSI, etc) are rounded off
to whole numbers before use. If the number is out of range, an error
message is generated.
Values of n for ROU command can be negative. This allows rounding to
nearest tens, hundreds, etc.
Parameter to FIX may be from 0 to 10, but only 6 digits are
significant.
All values of n in program statements must be integers, except for
CON statement. Simple statements (no parameters) take up 1 memory
location in the program storage array; statements with parameters
take 2, and CON statement takes 3.
Execution of a program can be aborted by pressing the ESC key.
To print program listing or program output on the printer, use the
filename PRN with the L and G commands.
The F command doesn't seem to be able to handle DOS directories,
probably because I'm using an early version of BASCOM. It will show
the directory of another drive, but you must include a filespec as
well as a drive letter (ie. B:*.*).
Invalid mathematical operations (for example, SQR of a negative
number), invalid branching instructions, etc. will result in an
appropriate error message. Other errors, such as entering an invalid
file name, will result in an "Input Error" message.
If entering statements at the control level (rather than in a
program line) the CON statement can be omitted. Just type a number
and CON is assumed.
For more information about this program please contact the author at
the address listed above, or via my bbs at 516-724-0971.
--------------------------------------------------------------------